package config

import (
	"github.com/robfig/config"
	"strings"
)

type Configure struct {
	Path    string
	Cg      *config.Config
	section string
}

func newConfigure() (*config.Config, error) {
	cg, err_ := config.ReadDefault("configure.ini")
	if err_ != nil {
		cg, _ = config.ReadDefault("config/configure.ini")
	}
	return cg, err_
}
func (cfg *Configure) PutValue(key string, value string) {
	if !cfg.Cg.HasSection(cfg.section) {
		cfg.Cg.AddSection(cfg.section)
	}
	cfg.Cg.AddOption(cfg.section, key, value)

}

func (cfg *Configure) GetValue(key string) string {

	if cfg.Cg.HasSection(cfg.section) {
		if cfg.Cg.HasOption(cfg.section, key) {
			v, err := cfg.Cg.RawString(cfg.section, key)
			if err == nil {
				v := strings.Trim(v, " ")
				return v

			}

		}
	}
	return ""
}
